package cn.edu.xcu.ckl.base;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

public abstract class BaseFragment  extends Fragment {
    protected View rootView;
    protected Context mContext;

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        mContext = context;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView =inflater.inflate(getContentView(),null);
        return rootView;
    }




    @Override
    public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        initView();

        setListener();
        initData();
    }


    /**
     * 加载布局文件
     */
    protected abstract int getContentView();


    /**
     * 初始化控件
     */
    protected abstract void initView();

    /**
     *监听事件
     */
    protected abstract void setListener();

    /**
     * 初始化数据
     */
    protected abstract void initData();


    protected void showToast(String msg) {
        Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();
    }



}
